package com.wfs.excel;

import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;

/**
 * @author: wfs
 * @Date: 2020/12/19 15:54
 * @Description:
 */
public class ExcelStyleUtils {

    private static void headerStylr(WriteCellStyle headerStyle) {
        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        headerStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
        headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
        headerStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        headerStyle.setWrapped(true);
        WriteFont headerFont = new WriteFont();
        headerFont.setColor(IndexedColors.WHITE.getIndex());
        // 字体大小
        headerFont.setFontHeightInPoints((short) 10);
        headerFont.setFontName("微软雅黑");
        headerStyle.setWriteFont(headerFont);
    }


    public static HorizontalCellStyleStrategy handlerStyleWrite() {
        // 头的策略
        WriteCellStyle titleStyle = new WriteCellStyle();
        // 垂直对齐
        titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        titleStyle.setLocked(true);
        titleStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
        titleStyle.setFillBackgroundColor(IndexedColors.YELLOW.getIndex());
        headerStylr(titleStyle);
        // 内容的策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
        //contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        // 背景绿色
        //contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
        //WriteFont contentWriteFont = new WriteFont();
        // 字体大小
        //contentWriteFont.setFontHeightInPoints((short) 20);
        //contentWriteFont.setBold(true);
        //contentWriteFont.setFontName("微软雅黑");
        //contentWriteCellStyle.setWriteFont(contentWriteFont);
        // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
        HorizontalCellStyleStrategy horizontalCellStyleStrategy =
                new HorizontalCellStyleStrategy(titleStyle, contentWriteCellStyle);
        return horizontalCellStyleStrategy;
    }

}
